type ImportVueFileType = typeof import("*.vue");
type ImportVueFileFnType = () => Promise<ImportVueFileType>;

const modulesFiles = import.meta.glob<ImportVueFileType>(
  "../../views/**/*.vue"
);

export const asyncRoutes = Object.entries(modulesFiles).reduce(
  (routes, [url, importFn]) => {
    // 使用正则表达式排除登录页和组件目录
    const excludeRegex = /(login|\/components\/)/i;
    if (!excludeRegex.test(url)) {
      const path = url.replace(/.+views\/|\.vue/gi, "");
      routes[path] = importFn;
    }

    return routes;
  },
  {} as Recordable<ImportVueFileFnType>
);
